package com.example.templateapp.ui.qrcode

import android.os.Bundle
import com.example.templateapp.R
import com.example.templateapp.databinding.ActivityGetQrBinding
import com.example.templateapp.ui.base.BaseAppCompatActivity
import com.example.templateapp.util.QRCodeUtils
import com.xuexiang.xutil.display.DensityUtils
import com.xuexiang.xutil.tip.ToastUtils

class GetQrActivity : BaseAppCompatActivity() {

    private val binding: ActivityGetQrBinding by binding(R.layout.activity_get_qr)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_get_qr)

        val content = getString(R.string.sample_string)
        val bitmap = QRCodeUtils.createQRCodeBitmap(
            content, DensityUtils.dip2px(300f), DensityUtils.dip2px(300f),
            "UTF-8", "L", "1",
            getColor(R.color.colorAccent), getColor(R.color.white)
        )

        binding.img.setImageBitmap(bitmap)

        binding.content.setOnClickListener {
            doContentClick()
        }

    }

    private var count = 5
    private fun doContentClick() {
        if (count == 0) {
            binding.content.setTextColor(getColor(R.color.colorPrimary))
            return
        }
        ToastUtils.toast("last ${count--} steps to open the door")

    }
}